﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web;
using System.Web.Script.Serialization;

namespace Sundry.App_Start.WebApi
{
    public class HttpMessage
    {
        #region 响应格式
        /// <summary>
        /// 设置http响应格式
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static HttpResponseMessage JsonFormat(string value) {
            HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(value, System.Text.Encoding.UTF8, "application/json") };
            return result;
        }
        /// <summary>
        /// 设置http响应格式
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static HttpResponseMessage JsonFormat(object value) {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(serializer.Serialize(value), System.Text.Encoding.UTF8, "application/json") };
            return result;
        }
        #endregion
    }
}